<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set value="${pageContext.request.contextPath}" var="path" scope="page"/>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>订单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../backstage/css/x-admin.css" media="all">
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>订单管理</cite></a>
            <a><cite>列表</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">ဂ</i>
        </a>
    </div>
    <div class="x-body">
        <form class="layui-form x-center" action="" style="width:70%">
            <div class="layui-form-pane" style="margin-top: 15px;">
                <div class="layui-form-item">
                    <label class="layui-form-label" >订单日期范围</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="开始日期" id="LAY_demorange_s">
                    </div>
                    <div class="layui-input-inline">
                        <input class="layui-input" placeholder="截止日期" id="LAY_demorange_e">
                    </div>
                    <div class="layui-input-inline">
                        <input id="id" type="text" name="id" placeholder="请输入用户ID" autocomplete="off" class="layui-input"
                               maxlength="10" onkeyup="value=this.value.replace(/\D+/g,'')">
                    </div>
                    <div class="layui-input-inline">
                        <select id="type" name="type">
                            <option value="">请选择订单类别</option>
                            <option value="商品结算">商品结算</option>
                            <option value="领取优惠券">领取优惠券</option>
                            <%--<option value="管理员修改">管理员修改</option>--%>
                            <%--<option value="签到活动">签到活动</option>--%>
                            <%--<option value="分享链接奖励">分享链接奖励</option>--%>
                            <%--<option value="充值会员">充值会员</option>--%>
                            <%--<option value="使用优惠券">使用优惠券</option>--%>
                            <%--<option value="每日首签">每日首签</option>--%>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select id="state" name="state">
                            <option value="">请选择订单状态</option>
                            <option value="订单未支付">订单未支付</option>
                            <option value="订单已支付">订单已支付</option>
                            <option value="订单已使用">订单已使用</option>
                            <option value="订单已过期">订单已过期</option>
                            <option value="订单已退款">订单已退款</option>
                            <option value="永久有效">永久有效</option>
                            <option value="订单已删除">订单已删除</option>
                            <option value="优惠券未使用">优惠券未使用</option>
                            <option value="优惠券已使用">优惠券已使用</option>
                            <option value="优惠券已过期">优惠券已过期</option>
                        </select>
                    </div>
                    <div class="layui-input-inline" style="width:80px">
                        <input type="button" id="search" class="layui-btn" lay-submit="" lay-filter="sreach" value="搜索">
                        </input>
                    </div>
                </div>
            </div>
        </form>

        <table class="layui-table">
            <thead>
                <tr>
                    <th>
                        ID
                    </th>
                    <th>
                        用户ID
                    </th>
                    <th>
                        商品名
                    </th>
                    <th>
                        宠物
                    </th>
                    <th>
                        购买人用户名
                    </th>
                    <th>
                        受保人用户名
                    </th>
                    <th>
                        类别
                    </th>
                    <th>
                        使用日期
                    </th>
                    <th>
                        截止日期
                    </th>
                    <th>
                        价格
                    </th>
                    <th>
                        积分
                    </th>
                    <th>
                        状态
                    </th>
                    <th>
                        支付方式
                    </th>
                    <th>
                        支付凭证
                    </th>
                    <th>
                        备注
                    </th>
                    <th>
                        操作
                    </th>
                </tr>
            </thead>
            <tbody id="bill_tbody">
                <tr>
                    <td>
                        /
                    </td>
                    <td>
                        /
                    </td>
                    <td>
                        /
                    </td>
                    <td>
                        /
                    </td>
                    <td>
                        /
                    </td>
                    <td>
                        /
                    </td>
                    <td>
                       /
                    </td>
                    <td>
                       /
                    </td>
                    <td>
                        /
                    </td>
                    <td >
                        /
                    </td>
                    <td >
                        /
                    </td>
                    <td >
                        /
                    </td>
                    <td >
                        /
                    </td>
                    <td >
                        /
                    </td>
                    <td >
                        /
                    </td>
                    <td class="td-manage">
                        <a title="编辑" href="javascript:;" onclick="order_edit('编辑','${path}/admin/billEdit','4','','510')" class="ml-5" style="text-decoration:none">
                            <i class="layui-icon">&#xe642;</i>
                        </a>
                    </td>
                </tr>
            </tbody>
        </table>
        <div id="page" style="margin-left: 650px;"></div>
    </div>
    <script src="../../../backstage/js/jquery.min.js"></script>
    <script src="../../../backstage/lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../backstage/js/x-layui.js" charset="utf-8"></script>
    <script>
    var layer = null;
    var form = null;
    layui.use(['laydate','element', 'laypage', 'layer', 'form'], function() {
        $ = layui.jquery;   //jquery
        laydate = layui.laydate;    //日期插件
        element = layui.element();   //面包导航
        laypage = layui.laypage;    //分页
        layer = layui.layer;    //弹出层
        var form = layui.form();    //弹出层(下拉列表)

        laypage({
            cont: 'page',
            pages: 100,
            first: 1,
            last: 100,
            prev: '<em><</em>',
            next: '<em>></em>'
        });

        //监听提交
        form.on('submit(*)', function(data) {
            console.log(data);
            //发异步，把数据提交给php
            layer.alert("增加成功", { icon: 6 });
            return false;
        });

        //日历控件的使用方法
        var start = {
            min: '1017-06-16 23:59:59',
            max: '2099-06-16 23:59:59',
            istoday: false, //今天的日期依然可以选择
            choose: function(datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas ;//将结束日的初始值设定为开始日
            }
        };
        var end = {
            min: '1017-06-16 23:59:59',
            max: '2099-06-16 23:59:59',
            istoday: false,
            choose: function(datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        document.getElementById('LAY_demorange_s').onclick = function() {
            start.elem = this;
            laydate(start);
        };
        document.getElementById('LAY_demorange_e').onclick = function() {
            end.elem = this;
            laydate(end);
        };

        $("#search").click(function() {
            var uid = $.trim($("#id").val());
            var state = $.trim($("#state").val());
            var type = $.trim($("#type").val());
            var beginDate = $.trim($("#LAY_demorange_s").val());
            var endDate = $.trim($("#LAY_demorange_e").val());

            $.ajax({
                type: 'POST',
                url: '/bill/searchByUser',
                dataType: "json",
                data: {
                    uid: uid,
                    beginDate: beginDate,
                    endDate: endDate,
                    billState:state,
                    billType:type
                },
                error: function () {
                    alert("查询失败");
                },
                success: function (data) {
                    console.info(JSON.stringify(data));
                    console.log(data);
                    console.log(data.bills);
                        var str = '';
                    if (data.bills.length != 0) {

                            for (var key in data) {
                                for (i = 0; i < data[key].length; i++) {
                                    var bill = data[key][i];
                                    console.log(bill);
                                    if(bill.type=="领取优惠券"){
                                    str += '<tr>';
                                    str += '  <td>' + bill.id + '</td>';
                                    str += '  <td>' + bill.user.id + '</td>';
                                    str += '  <td>' + bill.item.itemName + '</td>';
                                    str += '  <td>' +  "\ " + '</td>';
                                    str += '  <td>'+ "\ "+'</td>';
                                    str += '  <td>' +  "\ " + '</td>';
                                    str += '  <td>' + bill.type + '</td>';
                                    str += '  <td>' +  "\ " + '</td>';
                                    str += '  <td>' +  "\ "+ '</td>';
                                    str += '  <td>' + bill.price + '</td>';
                                    str += '  <td>' + bill.credit + '</td>';
                                    str += '  <td>' + bill.state + '</td>';
                                    str += '  <td>' +  "\ " + '</td>';
                                    str += '  <td>' + bill.proof + '</td>';
                                    str += '  <td>' +  bill.remark + '</td>';
                                    str += '  <td>' + "不可操作" + '</td>';
                                    str += '</tr>';
                                }else if(bill.type=="商品结算"&&bill.state=="订单未支付") {
                                        str += '<tr>';
                                        str += '  <td>' + bill.id + '</td>';
                                        str += '  <td>' + bill.user.id + '</td>';
                                        str += '  <td>' + bill.item.itemName + '</td>';
                                        str += '  <td>' + bill.pet.name + '</td>';
                                        str += '  <td>' +  "\ " + '</td>';
                                        str += '  <td>' + bill.insured.name + '</td>';
                                        str += '  <td>' + bill.type + '</td>';
                                        str += '  <td>' +  "\ "+ '</td>';
                                        str += '  <td>' +  "\ " + '</td>';
                                        str += '  <td>' + bill.price + '</td>';
                                        str += '  <td>' + bill.credit + '</td>';
                                        str += '  <td>' + bill.state + '</td>';
                                        str += '  <td>' +  "\ " + '</td>';
                                        str += '  <td>' +  "\ "+ '</td>';
                                        str += '  <td>' +  "\ " + '</td>';
                                        str += '  <td class="td-manage"> <a title="编辑" class="ml-5" style="text-decoration:none" href="javascript:void(0)" onclick="order_edit(this)" data-id=' + bill.id + ' >' + ' <i class="layui-icon">' + "&#xe642;" + '</i> </a> </td>';
                                        str += '</tr>';
                            }else if(bill.type=="商品结算"&&bill.state=="订单已删除") {
                                        str += '<tr>';
                                        str += '<tr>';
                                        str += '  <td>' + bill.id + '</td>';
                                        str += '  <td>' + bill.user.id + '</td>';
                                        str += '  <td>' + bill.item.itemName + '</td>';
                                        str += '  <td>' + bill.pet.name + '</td>';
                                        str += '  <td>' +  "\ " + '</td>';
                                        str += '  <td>' + bill.insured.name + '</td>';
                                        str += '  <td>' + bill.type + '</td>';
                                        str += '  <td>' +  "\ "+ '</td>';
                                        str += '  <td>' +  "\ " + '</td>';
                                        str += '  <td>' + bill.price + '</td>';
                                        str += '  <td>' + bill.credit + '</td>';
                                        str += '  <td>' + bill.state + '</td>';
                                        str += '  <td>' +  "\ " + '</td>';
                                        str += '  <td>' +  "\ "+ '</td>';
                                        str += '  <td>' +  "\ " + '</td>';
                                        str+='<td>' + "不可操作" + '</td>';
                                        str += '</tr>';
                                    } else{
                                        str += '<tr>';
                                        str += '  <td>' + bill.id + '</td>';
                                        str += '  <td>' + bill.user.id + '</td>';
                                        str += '  <td>' + bill.item.itemName + '</td>';
                                        str += '  <td>' + bill.pet.name + '</td>';
                                        str += '  <td>' +  bill.buyer.name + '</td>';
                                        str += '  <td>' + bill.insured.name + '</td>';
                                        str += '  <td>' + bill.type + '</td>';
                                        str += '  <td>' +  bill.useDate+ '</td>';
                                        str += '  <td>' +  bill.expireDate + '</td>';
                                        str += '  <td>' + bill.price + '</td>';
                                        str += '  <td>' + bill.credit + '</td>';
                                        str += '  <td>' + bill.state + '</td>';
                                        str += '  <td>' +  bill.buyWay + '</td>';
                                        str += '  <td>' + bill.proof+ '</td>';
                                        str += '  <td>' +  bill.remark + '</td>';
                                        str+='<td>' + "不可操作" + '</td>';
                                        str += '</tr>';
                                    }
                                }
                            }
                                $('#bill_tbody').html(str);
                    }else{
                        var input = "找到0条记录";
                        $('#bill_tbody').html(input);
                    }
                }

            });
        });
    });


    //批量删除
    function delAll() {
        layer.confirm('确认要删除吗？', function(index) {
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', { icon: 1 });
        });
    }
    function order_edit(bill) {
        //console.log($(product).data("id"));

        //将localStorage传递到哪个页面
        //location.href = 'product-edit.jsp';
        //设置localStorage
        window.localStorage.setItem('msg',$(bill).data("id"));
        x_admin_show("编辑", "${path}/admin/billEdit", 510,400);
    }
    // 删除
    function rule_del(obj, id) {
        layer.confirm('确认要删除吗？', function(index) {
            //发异步删除数据
            layer.msg('已删除!', { icon: 1, time: 1000 });
        });
    }


    </script>
</body>

</html>